var divsToStyle = new Array("home", "left_nav", "footer", "about", "fleet", "rates", "reservations", "contact");

function addLoadEvent(func)
{
    var oldonload = window.onload;
    if(typeof window.onload != 'function')
    {
        window.onload = func;
    }
    else
    {
        window.onload = function()
        {
            oldonload();
            func();
        }
    }
}
function toggleTables(element)
{
    var table;
    element.parentNode.className = "current";
    switch(element.id)
    {
        case "limo_link":
            document.getElementById("suv_link").parentNode.className = "";
            document.getElementById("policy_link").parentNode.className = "";
            document.getElementById("limo_table").style.display = "block";
            //document.getElementById("sedan_table").style.display = "none";
            document.getElementById("suv_table").style.display = "none";
            document.getElementById("policies").style.display = "none";
            break;
        case "suv_link":
            document.getElementById("limo_link").parentNode.className = "";
            document.getElementById("policy_link").parentNode.className = "";
            document.getElementById("suv_table").style.display = "block";
            document.getElementById("limo_table").style.display = "none";
            document.getElementById("policies").style.display = "none";
            break;
        case "policy_link":
            document.getElementById("limo_link").parentNode.className = "";
            document.getElementById("suv_link").parentNode.className = "";
            document.getElementById("suv_table").style.display = "none";
            document.getElementById("limo_table").style.display = "none";
            document.getElementById("policies").style.display = "block";
            break;
        default:
            //do nothing
    }
}

function showReservationField(check)
{
    var section = $('pick_up');
    if(check.checked)
    {
        new Effect.Appear(section);
    }
    else
    {
        new Effect.Fade(section);
    }
    matchDivHeights();
}

function prepareTabs()
{
    if(!document.getElementsByTagName) return false;
    if(!document.getElementById) return false;
    if(!document.getElementById("tabs")) return false;
    
    var tabs = document.getElementById("tabs");
    var links = tabs.getElementsByTagName("a");
    for(var i = 0; i < links.length; i++)
    {
        links[i].onclick = function() {
            toggleTables(this);
            matchDivHeights();
            return false;
        }
    }
}

function prepareCheckBox()
{
    if(!$('round_trip')) return false;
    if(!$('pick_up')) return false;
    $('round_trip').onclick= function () { showReservationField(this); }
    if(!$('round_trip').checked) new Effect.Fade($('pick_up'));
}

function matchDivHeights()
{
    var arr = document.getElementsByClassName("main", $("main"), "div");
    var nav = $("nav_container");
    var main = arr[0];
    if(main)
    {
        if(nav.offsetHeight < main.offsetHeight)
        {
            nav.style.height = main.offsetHeight + 'px';
        }
        else
        {
            main.style.height = nav.offsetHeight + 'px';
        }
    }
}

function detectResolution()
{
    dimObj = $('body').getDimensions();

    /*if(dimObj.width <= 1024)
    {
        $('small').disabled = false;
        if($('ie_small')) $('ie_small').disabled = false;
        
        $('logo').src = 'images/amtranslogo-7-small.gif';
        var links = $('main_nav').getElementsByTagName('a');
        
        for(var i = 0; i < links.length; i++)
        {
            links[i].className = '';
            links[i].className= 'nav_image_small';
        }
    }
    else
    {
       $('small').disabled = true;
        if($('ie_small')) $('ie_small').disabled = true;
    }
    <%= stylesheet_link_tag 'alternate_small', { :id => 'small'} %>
    <%= stylesheet_link_tag 'ie_alternate_small', { :id => 'ie_small'} %> 
    */
    matchDivHeights();
}
addLoadEvent(prepareTabs);
addLoadEvent(prepareCheckBox);
//addLoadEvent(matchDivHeights);